<?php  
class CustomEventHandler {  
    static function handleMissingTranslation($event) {  
		$filepath = $_SERVER['DOCUMENT_ROOT']."protected/messages/".$event->language."/";
		$filename = $event->category.".php";
		if (!file_exists($filepath)) {
			mkdir($filepath, 0755, true);
		}
		if (file_exists($filepath.$filename)) {
			$translate = require($filepath.$filename);
		} else {
			$translate = array();
		}
		$content = "<?php"."\r\n";
		$content .= "return array("."\r\n";
		foreach ($translate as $key => $value){
			$content .= "\t\t"."'".$key."'=>'".$value."',"."\r\n";
		}
		$content .= "\t\t"."'".$event->message."' => '". $event->message ."',"."\r\n";
		$content .= ");"."\r\n";
		file_put_contents($filepath.$filename, $content);
    }  
}